﻿@model ShoppingCartModel
@using Nop.Core
@using Nop.Core.Infrastructure
@using Nop.Web.Models.ShoppingCart;
@{
    var webHelper = EngineContext.Current.Resolve<IWebHelper>();
}
<div class="order-summary-content">
    @Html.Widget("order_summary_content_before")
    @Html.Partial("_OrderReviewData", Model.OrderReviewData)
    @if (Model.Items.Count > 0)
    {
        if (Model.Warnings.Count > 0)
        {
            <div class="message-error">
                <ul>
                    @foreach (var warning in Model.Warnings)
                    {
                        <li>@warning</li>
                    }
                </ul>
            </div>
        }
        <div class="clearfix">
            @*we add enctype = "multipart/form-data" because "File upload" attribute control type requires it*@
            @using (Html.BeginRouteForm("ShoppingCart", FormMethod.Post, new { enctype = "multipart/form-data" }))
            {
            <div class="left-side">
                @*cart products module*@
                @Html.Partial("_OrderCartProducts", Model)
                @if (!String.IsNullOrEmpty(Model.CheckoutAttributeInfo))
                {
                    <div class="selected-checkout-attributes">
                        @Html.Raw(Model.CheckoutAttributeInfo)
                    </div>
                }
                <div class="buttons">
                    @if (Model.IsEditable)
                    {
                        <div class="common-buttons">
                            <input type="submit" name="updatecart" id="updatecartbtn" value="@T("ShoppingCart.UpdateCart")" class="btn btn-default update-cart-button" />
                            <input type="submit" name="continueshopping" value="@T("ShoppingCart.ContinueShopping")" class="btn btn-default continue-shopping-button" />
                        </div>
                        @Html.Partial("_CheckoutAttributes", Model.CheckoutAttributes, new ViewDataDictionary())
                    }
                </div>
                <div class="cart-footer">
                    @Html.Widget("order_summary_cart_footer")
                    @if (Model.IsEditable)
                    {
                        if (!String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                        {
                            <div>
                                <div class="min-amount-warning">
                                    @Model.MinOrderSubtotalWarning
                                </div>
                            </div>
                        }
                    }

                    @if (Model.IsEditable)
                    { <div class="cart-collaterals">
                        <div class="title">
                            Have Promotion Code?
                        </div>
                        <div class="deals">
                            @Html.Partial("_DiscountBox", Model.DiscountBox)
                            @Html.Partial("_GiftCardBox", Model.GiftCardBox)
                            @Html.Widget("order_summary_content_deals")
                        </div>
                    </div>

                        <div class="addon-buttons">
                            @*Payment method buttons (e.g. GoogleCheckoutButton, Paypal Express)*@
                            @Html.Partial("_ButtonPaymentMethod", Model)
                        </div>
                    }
                </div>
            </div>
            <!-- shopping cart summary total -->
            <div class="right-side">
                <div class="cart-sidebar">
                    @*order total module*@
                    @Html.Action("OrderTotals", "ShoppingCart", new { isEditable = Model.IsEditable })
                    @if (Model.IsEditable)
                    {
                        if (Model.TermsOfServiceOnShoppingCartPage)
                        {
                            <div class="terms-box">
                                <div id="terms-of-service-warning-box" title="@T("Checkout.TermsOfService")" style="display:none;">
                                    <p>@T("Checkout.TermsOfService.PleaseAccept")</p>
                                </div>
                                <div class="terms-of-service">
                                    <input id="termsofservice" type="checkbox" name="termsofservice" />
                                    <span class="text">@T("Checkout.TermsOfService.IAccept")</span>
                                    <span class="read" data-openurl='@Url.RouteUrl("TopicPopup", new { SystemName = "conditionsofuse" })'>@T("Checkout.TermsOfService.Read")</span>
                                </div>
                            </div>
                            <script type="text/javascript">
                                seajs.use("common/1.0.0/index", function (app) {
                                    app(function () {
                                        app(".terms-of-service .read").on("click", function () {
                                            var url = app(this).data("openurl");
                                            app.openWindow(url, 450, 500, true);
                                        });
                                    });
                                });
                            </script>
                        }

                        if (String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                        { //order checkout button
                            <div class="process-to-checkout">
                                <button type="submit" id="checkout" name="checkout" value="checkout" class="btn btn-primary process-check-btn checkout-button">
                                    @T("Checkout.Button")
                                </button>
                            </div>
                            <script type="text/javascript">
                                seajs.use("common/1.0.0/index", function (app) {
                                    app(function () {
                                        app('#checkout').click(function () {
                                            //terms of service
                                            var termOfServiceOk = true;
                                            if (app('#termsofservice').length > 0) {
                                                //terms of service element exists
                                                if (!app('#termsofservice').is(':checked')) {
                                                    var $dialogHtml = app("#terms-of-service-warning-box");
                                                    var title = '<div class="c-header"><i class="error-icon"></i><span>Accept the terms</span><i class="close" title="close"></i></div>';
                                                    app.alert.show(title, $dialogHtml.html(), 400, null);
                                                    termOfServiceOk = false;
                                                } else {
                                                    termOfServiceOk = true;
                                                }
                                            }
                                            return termOfServiceOk;
                                        });
                                    });

                                });
                            </script>
                        }
                        // estimaate shipping.
                        @Html.Partial("EstimateShipping", Model.EstimateShipping)
                    }
                </div>

            </div>
            }
        </div>
        if (Model.IsEditable)
        {
            @Html.Action("CrossSellProducts", "Product")
        }
    }
    else
    {
        @T("ShoppingCart.CartIsEmpty")
    }
    @Html.Widget("order_summary_content_after")
</div>
